<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/3 0003
 * Time: 14:53
 */

namespace app\common\tools;


class Arr
{
    /**
     * 递归实现无限极分类
     * @param $array array 数组
     * @param $pid int 父id
     * @return array
     */
    public static function tree($array, $pid)
    {
        $tree = array();
        foreach ($array as $key => $value) {
            if ($value['pid'] == $pid) {
                $value['son'] = self::tree($array, $value['id']);
                if (!$value['son']) {
                    unset($value['son']);
                }
                $tree[] = $value;
            }
        }
        return $tree;
    }

}